home *** CD-ROM | disk | FTP | other *** search
- Path: sourcery.han.de!not-for-mail
- Newsgroups: comp.sys.amiga.programmer
- References: <1143.6601T709T2673@mbox3.swipnet.se>
- From: "Olaf Barthel" <olsen@sourcery.han.de>
- Date: Mon, 29 Jan 1996 14:19:00 +0100
- X-NewsReader: IntuiNews 1.3a (7.9.95)
- Subject: Re: Localisation
- Message-ID: <13213535@sourcery.han.de>
-
- In Article <1143.6601T709T2673@mbox3.swipnet.se>, Roland Bengtsson <roland.bengtsson@mbox3.swipnet.se> wrote:
- > I took a look at the locale example at the NDK disk, but I winder if this really is the most effective way to go?
- >
- > They use a function GetString() that compare localeID with each member in the localelist,
- > when it is needed. Of course it doesn't matter, but maybe in a big program with many strings
- > on a 68000 without cache. I have never done localisation, but I have a project who need it.
- >
- > Is it possible to use:
- >
- > enum { MSG_HELLO, MSG_BYE, NUMSTRINGS };
- >
- > Then call the list with localestring[MSG_BYE] for example;
-
- This will only work if there is a string assigned to each ID and there
- are no gaps between IDs.
-
- > I would appreciate if someone could send a short example in email or here if this is possible.
- >
- > If the NDK disk is the best way, please explain why!
-
- Per se it is not the best way to iterate through the entire database
- to look up a single string. However, with small databases the overhead is
- neglegible. If your database contents are sorted in ascending order (which
- CatComp unfortunately does not enforce) you could use a simple binary
- search to look up the string. Here is some modified piece of code I use
- in my `term' application; it assumes that the strings are stored in
- "AppStrings" and "NumAppStrings" holds the number of entries in the database.
-
- ----------------------------------8<---------------------------------
-
- STRPTR
- GetString(ULONG ID)
- {
- STRPTR Builtin;
- LONG Left,Mid,Right;
-
- Left = 0;
- Right = NumAppStrings - 1;
-
- do
- {
- Mid = (Left + Right) / 2;
-
- if(ID < AppStrings[Mid].cca_ID)
- Right = Mid - 1;
- else
- Left = Mid + 1;
- }
- while(ID != AppStrings[Mid].cca_ID && Left <= Right);
-
- if(ID == AppStrings[Mid].cca_ID)
- Builtin = AppStrings[Mid].cca_Str;
- else
- Builtin = "";
-
- if(Catalog)
- {
- STRPTR String = GetCatalogStr(Catalog,ID,Builtin);
-
- if(String[0])
- return(String);
- }
-
- return(Builtin);
- }
-
- --
- Home: Olaf Barthel, Brabeckstrasse 35, D-30559 Hannover
- Net: olsen@sourcery.han.de
-